package android.itv.library;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.itv.model.Programe;

public class JsonPrase
{
    public static ArrayList<Programe> parseSchedule(String schedule)
    {

	ArrayList<Programe> listpro=new ArrayList<Programe>();	
	Programe pro;
	JSONObject jsonObj;
	
        try
        {
	    jsonObj = new JSONObject(schedule);
	    JSONArray jschedule=jsonObj.getJSONArray("schedule");
	    for(int i=0;i<jschedule.length();i++)
	    {
		pro=new Programe();
		pro.setTime(jschedule.getJSONObject(i).getString("time"));
		pro.setTitle(jschedule.getJSONObject(i).getString("title"));
		pro.setDescription(jschedule.getJSONObject(i).getString("description"));
		
		listpro.add(pro);
	    }
        }
        catch (JSONException e)
        {
	    e.printStackTrace();
        }
	
        return listpro;
    }
}
